/**
 * keywords mongoose dao(CURD)
 */

var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    ObjectId = require('mongoose').Types.ObjectId,
    wechatSchema;

var wechat = mongoose.createConnection('mongodb://scrapy:scrapy.pwd@111.204.165.5:27017/scrapy');


// 完整的keywords
wechatSchema = new Schema({
    post_time:Date,
    author:String,
    like_num:Number,
    read_num:Number,
    title:String,
    trim_content:String,
    keywords:Array,
    sentiment:Number
});

//静态方法
wechatSchema.statics.findByList = function(keyword, callback) {
    console.log('keyword:'+keyword);
            var re = new RegExp(keyword);
            return Wechat.find({$or:[{'title': re},{'trim_content.content':re}]}, {
                post_time:1,
                author:1,
                like_num:1,
                read_num:1,
                title:1,
                trim_content:1,
                keywords:1,
                sentiment:1
            }, callback);

};


// 激活model
var Wechat = wechat.model('weixin', wechatSchema),w = new Wechat;
w.save(function(){
    console.log('wechat连接成功');
});


exports.Wechat = Wechat;
